package mx.itesm.twritter.shared.map;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Node implements IsSerializable, Comparable<Node> {

	private int id;
	private double latitude;
	private double longitude;
	private List<Way> ways; // it is a way if ways.size() > 1
	private Map<String, String> tags;
	
	public Node() {
		this.ways = new ArrayList<Way>();
	}
	
	public Node(double latitude, double longitude) {
		this(0, latitude, longitude);
	}
	
	public Node(int id, double latitude, double longitude) {
		this.id = id;
		this.latitude = latitude;
		this.longitude = longitude;
		this.ways = new ArrayList<Way>();
	}
	
	public Node(int id, double latitude, double longitude,
			Map<String, String> tags) {
		this.id = id;
		this.latitude = latitude;
		this.longitude = longitude;
		this.ways = new ArrayList<Way>();
		this.tags = tags;
	}
	
	public String toString() {
		String ret = "Node " + id + "; lat = " + this.latitude + ", lon = " + this.longitude + ";\n";
		if(ways.size() > 1) {
			ret += "Crosses with\n";
			for(Way w : this.ways) {
				ret += "  " + w.getName() + "\n";
			}
		}
		
		return ret;
	}
	
	public String toStringWithoutCrosses() {
		String ret = "Node " + id + "; lat = " + this.latitude + ", lon = " + this.longitude + ";";
		return ret;
	}
	
	@Override
	public boolean equals (Object o) {
		if(!(o instanceof Node)) {
			return false;
		}
		
		Node n = (Node)o;
		return this.id == n.getId();
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLatitude(double latitude) {
		this.latitude = latitude;
	}

	public double getLongitude() {
		return longitude;
	}

	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}

	public Map<String, String> getTags() {
		return tags;
	}

	public void setTags(Map<String, String> tags) {
		this.tags = tags;
	}

	public List<Way> getWays() {
		return ways;
	}

	public void setWays(List<Way> ways) {
		this.ways = ways;
	}

	@Override
	public int compareTo(Node o) {
		return this.id - o.getId();
	}
	
}
